package com.qifan.energy.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.qifan.energy.R;
import com.qifan.energy.adapter.ImageNetAdapter;
import com.qifan.energy.bean.result.HomeListResult;
import com.qifan.energy.util.UIUtils;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.transformer.AlphaPageTransformer;

import java.util.ArrayList;
import java.util.List;

public class CustomBannerView extends ConstraintLayout {

    private Banner homeBanner;
    private List<HomeListResult.AdvertiseListBean> images = new ArrayList();

    public CustomBannerView(Context context) {
        super(context);

        View inflate = inflate(getContext(), R.layout.item_banner_home, this);
        homeBanner = inflate.findViewById(R.id.home_banner);
        homeBanner.setBackgroundResource(R.mipmap.icon_banner_default);
        homeBanner.setIndicator(new CircleIndicator(context));
        homeBanner.setIndicatorNormalColorRes(R.color.bg_gray);
        homeBanner.setIndicatorSelectedColorRes(R.color.system_color);
        homeBanner.setAdapter(new ImageNetAdapter(images));
        homeBanner.setBackgroundColor(UIUtils.getColor(R.color.system_color));
        homeBanner.setBannerGalleryEffect(10,10);//添加透明效果(画廊配合透明效果更棒)
        homeBanner.addPageTransformer(new AlphaPageTransformer());
    }

    public CustomBannerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomBannerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setImages(List<HomeListResult.AdvertiseListBean> images) {
        this.images = images;
        homeBanner.setDatas(images);
    }
}
